package flirtme.activities;

import java.util.ArrayList;
import java.util.HashMap;



import com.ans.flirtme.R;
import com.ans.flirtme.R.layout;
import com.ans.flirtme.R.menu;

import flirtme.constants.Constants;
import flirtme.libraries.imageloader.ImageLoader;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.TextView;

public class ShowProfileActivity extends Activity {
	HashMap<String, String> interests = null;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_show_profile);
		
		ImageView imageView = (ImageView) this.findViewById(R.id.profile_avatar_contact_user);
		TextView userName = (TextView) this.findViewById(R.id.profile_username);
		TextView firstname = (TextView) this.findViewById(R.id.profile_user_firstname);
		TextView lastname = (TextView) this.findViewById(R.id.profile_user_lastname);
		TextView email = (TextView) this.findViewById(R.id.profile_email);
		TextView gender = (TextView) this.findViewById(R.id.profile_gender);
		TextView age  = (TextView) this.findViewById(R.id.profile_age);
		TextView birdthDate  = (TextView) this.findViewById(R.id.profile_birth_date);
		TextView interests  = (TextView) this.findViewById(R.id.profile_interests);
		
		Intent intent = this.getIntent();
		
		
		String extra = intent.getStringExtra(Constants.AVATAR_URL);
		ImageLoader imageLoader = new ImageLoader(this);
		imageLoader.DisplayImage(extra, imageView);
		
		extra = intent.getStringExtra(Constants.USER_NAME);
		userName.setText(extra);
		
		extra = intent.getStringExtra(Constants.FIRST_NAME);
		firstname.setText(extra);
		
		extra = intent.getStringExtra(Constants.LAST_NAME);
		lastname.setText(extra);
		
		extra = intent.getStringExtra(Constants.EMAIL);
		email.setText(extra);
		
		extra = intent.getStringExtra(Constants.GENDER);
		Boolean male = extra.equalsIgnoreCase("m"); 
		String genderString = male? "Male" : "Female";
		gender.setText(genderString);
		
		extra = intent.getStringExtra(Constants.AGE);
		age.setText(extra);
		
		extra = intent.getStringExtra(Constants.BIRTH_DATE);
		birdthDate.setText(extra);
		
		this.createInterestsHashMap();
		extra = intent.getStringExtra(Constants.INTERESTS);
		parseInterests(interests, extra);
	}

	private void createInterestsHashMap() {
		interests = new HashMap<String, String>();
		interests.put("1",  "Bares y restaurantes");
		interests.put("2",  "Heladerías y Cafés");
		interests.put("3",  "Salud y belleza");
		interests.put("4",  "Viajes y turismo");
		interests.put("5",  "Teatros");
		interests.put("6",  "Cines");
		interests.put("7",  "Deportes");
		interests.put("8",  "Tecnologías");
		interests.put("9",  "Indumentaria y calzados");
		interests.put("10",  "Mascotas");
		interests.put("11",  "Vehículos");
		interests.put("12",  "Cursos y aprendizaje");
		interests.put("13",  "Universidades");
		interests.put("14",  "Librerías");

	}

	private void parseInterests(TextView _interests, String extra) {
		String[] list = extra.split("[,]");
		ArrayList<String> interestsStringArray = new ArrayList<String>();
		for (String string : list) {
			String interestString = interests.get(string);
			interestsStringArray.add(interestString);
		}
		String result = interestsStringArray.toString();
		_interests.setText(result);
		
	}

	public void onBackListener(View view) {
		 super.onBackPressed();
	}
	
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.show_profile, menu);
		return true;
	}

}
